﻿@model LastoRevival.Service.Contracts.Models.MessageThread
@using LastoRevival.Service.Contracts.Models;

@{
	
	var linkActive = true;

	// moderators can always view
	if (Model.PostDetails.Locked && !((UserProfile)ViewBag.UserProfile).CanModerate(Model.PostDetails.ForumID))
	{
		linkActive = false;
	}

	// disable if this is the active post
	if ((ViewData["ActivePostID"] != null && Model.PostDetails.PostID == (int)ViewData["ActivePostID"]))
	{
		linkActive = false;
	}
	
	var lockedString = Model.PostDetails.Locked ? "locked" : "";

	var messageUrl = Url.Action("ViewPost", "Post", new { postID = Model.PostDetails.PostID }, null);
	var oddEven = ViewBag.Level % 2 == 0 ? "even" : "odd";
}

@* I hate having mobile spaghetti code in here, but I don't see another way, because the mobile theme requires the divs in a different order *@

@if (Html.IsMobile())
{
	<div class="message-details" onclick="redirect('@messageUrl')">
		@* in the mobile views, username from the message list is not clickable.  This keeps the UI easier for touch users *@
		<span class="author @Model.PostDetails.GroupName">@Model.PostDetails.UserName</span>
	
		<span class="date">@Html.AdjustedTime(Model.PostDetails.DatePosted).ToString(LanguageLoader.GetWord("MobileTimestampFormat"))</span>
	</div>
}

<div class="message-title @oddEven">
	@if (!linkActive)
	{
		<span class="title active @lockedString">@Model.PostDetails.Subject</span>
	}
	else
	{
		<span class="title"><a class="@lockedString" href="@messageUrl">@Model.PostDetails.Subject</a></span>
	}

	@if (!Model.PostDetails.HasText)
	{
		<span class="notext-marker">@LanguageLoader.GetWord("NoText")</span>
	}
</div>

@if (!Html.IsMobile())
{
	<div class="message-details">
		@if (Model.PostDetails.UserID != UserProfileDetails.AnonymousUserID)
		{
			<a class="author @Model.PostDetails.GroupName" href="@Url.Action("ViewUser", "User", new { username = Model.PostDetails.UserName })"> @Model.PostDetails.UserName</a>
		}
		else
		{		
			<span class="author @Model.PostDetails.GroupName">@Model.PostDetails.UserName</span>
		}
		<span class="date">@Html.AdjustedTime(Model.PostDetails.DatePosted).ToString(LanguageLoader.GetWord("TimestampFormat"))</span>
		<span class="views">@string.Format(LanguageLoader.GetWord("ViewsFormat"), Model.PostDetails.Views)</span>
		<span class="replies">@string.Format(LanguageLoader.GetWord("RepliesFormat"), Model.ChildPosts.Count())</span>
	</div>
}